package org.langqiao.network.java复习题老师给的;
/*import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
*/
import java.io.*;
import java.net.*;
public class shuZu extends Thread{
	public shuZu(){}
	public void run() //执行线程的Run（）方法
	{  
	  ServerSocket serversocket = null;//定义一个serversocket对象
	  Socket socket = null;//定义一个socket对象
	  InputStream in = null;//输入流
	  OutputStream out = null;//输出流
	  BufferedReader br = null;
      try 
      {
		   System.out.println("服务器IP：" + InetAddress.getLocalHost().getHostAddress()); //打印服务器信息
		   //InetAddress.getLocalHost().getHostAddress()返回本地主机的ip地址以字符窜文本形式表示出来
		   System.out.println("正在等待连接...");
		   serversocket = new ServerSocket(9000); //建立Socket连接，指定端口号9000
		   socket = serversocket.accept();   //接受客户连接
		   if (serversocket.isBound()) 
		   {//返回ServerSocket的绑定状态
		       System.out.println("连接中...");
	       }
	       in = socket.getInputStream();   //得到输入流
	       out = socket.getOutputStream();   //得到输出流
	  } 
      catch (Exception e) 
      {
		   // 错误处理
		   //e.printStackTrace();
	  }
	  while(true)
	  {
		   //接收
		   try 
		   {
			    byte[] receive = new byte[200];//定义一个字节数组
			    in.read(receive);     //读出输入流中的数据
			    String instr = new String(receive);//定义一个instr字符窜
			    System.out.print("客户机消息：" + instr.trim() + "\n"); //打印客户机发过来的消息
	       } 
		   catch (Exception e) {
	    // 错误处理
	    //e.printStackTrace();
	       }
	   //发送
	      try 
	      {
		    System.out.print("服务器消息：");
		    br = new BufferedReader(new InputStreamReader(System.in)); 
		    String outstr = null;
		    outstr = br.readLine(); //得到输入的信息
		    byte[] send = outstr.getBytes();
		    out.write(send);  //发送信息
	      }
	      catch (Exception e) {
	    // 错误处理
	    //e.printStackTrace();
	   }
    }
  }
  public static void main(String[] args) {

	  new Server().start(); //启动服务器线程
  }
}

